package com.mokio.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mokio.entity.ProductInfo;
import com.mokio.entity.ProductInfoExample;
import com.mokio.mapper.ProductInfoMapper;
import com.mokio.service.ProductInfoService;
import com.mokio.vo.ProductInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: xiaomishop
 * @ClassName ProductInfoServiceImpl
 * @description:
 * @author: mokio
 * @create: 2024−12-10 19:19
 * @Version 1.0
 **/
@Service
public class ProductInfoServiceImpl implements ProductInfoService {

    @Autowired
    public ProductInfoMapper productInfoMapper;

    /**
     * 进行分页存储返回
     * @param pageNo
     * @param pageSize
     * @return
     */
    public PageInfo<ProductInfo> getProductInfoByPage(Integer pageNo, int pageSize) {
        ProductInfoExample example = new ProductInfoExample();
        //使用分页  必须优先设置这个方法 !!!!
        PageHelper.startPage(pageNo,pageSize);
        //查询全部的数据
        List<ProductInfo> productInfos = productInfoMapper.selectByExample(example);
        //将集合给分页类
        PageInfo<ProductInfo> pageInfo = new PageInfo<>(productInfos);
        return pageInfo;
    }

    /**
     * 多条件组合查询
     * @param vo
     * @param pageSize
     * @return
     */

    @Override
    public PageInfo<ProductInfo> getProductInfoByVo(ProductInfoVo vo, Integer pageSize) {
        //使用分页  必须优先设置这个方法 !!!!
        PageHelper.startPage(vo.getPage(),pageSize);

        List<ProductInfo> productInfoList=  productInfoMapper.selectByVo(vo);

        PageInfo<ProductInfo> pageInfo = new PageInfo<ProductInfo>(productInfoList);

        return pageInfo;
    }


    @Override
    public ProductInfo findProductById(Integer pid) {
        ProductInfo productInfo = productInfoMapper.selectByPrimaryKey(pid);
        return productInfo;
    }

    @Override
    public void batchDel(Integer[] ids) {
        productInfoMapper.batchDel(ids);
    }

    @Override
    public void deleteById(Integer id) {
        ProductInfoExample example = new ProductInfoExample();
        example.createCriteria().andPIdEqualTo(id);
        int i = productInfoMapper.deleteByExample(example);
    }

    @Override
    public void updateByInfo(ProductInfo productInfo) {
        productInfoMapper.updateByPrimaryKeySelective(productInfo);
    }

    @Override
    public void save(ProductInfo product) {
        productInfoMapper.insert(product);
    }
}
